package com.weixin.engine.daily.qqhr;

import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author wangchunhui
 * @date 2022/11/1 13:53
 */
public class SignatureMechanism {

    /**
     * 签名拼接函数
     *
     * @param param 参数 key-value 对
     * @return
     */
    private String getSign(HashMap<String, Object> param) {
        Map<String, Object> result = new LinkedHashMap<String, Object>();
        param.entrySet().stream().sorted(Map.Entry.comparingByKey()).forEachOrdered(x -> result.put(x.getKey(), x.getValue()));
        StringBuilder signStringBuilder = new StringBuilder();
        for (Map.Entry<String, Object> entry : result.entrySet()) {
            signStringBuilder.append("&").append(entry.getKey()).append("=").append(entry.getValue());
        }
        return signStringBuilder.substring(1);
    }
}
